package gd.qaq.blue.boundary.util;

import gd.qaq.blue.boundary.Boundary;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.Plugin;


@SuppressWarnings("all")
public class PluginHelper {

    public static FileConfiguration loadData(Plugin plugin) {
        plugin.saveDefaultConfig();
        return plugin.getConfig();
    }

    public static void reload(Boundary plugin, CommandSender p) {
        if (p.isOp()) {
            try {
                plugin.reloadConfig();
                plugin.config = plugin.getConfig();
                plugin.initData();
                success(p, "插件重载成功");
            } catch (Exception e) {
                e.printStackTrace();
                error(p, "插件重载失败!");
            }
        }
    }

    public static String colorFormat(String str) {
        return str.replace("&", "§");
    }

    public static void success(CommandSender p, String str) {
        p.sendMessage(colorFormat(Boundary.config.getString("plugin.prefix.success") + str));
    }

    public static void error(CommandSender p, String str) {
        p.sendMessage(colorFormat(Boundary.config.getString("plugin.prefix.error") + str));
    }
}
